#### Generates Point Figures for Alternative Demographics ####

## Party

# Agree/Disagree
fig_pid_dat = bind_rows(import(here("data","fig_pid_agree_dat.rds")) |> 
                          mutate(agree = "Agree"),
                        import(here("data","fig_pid_disagree_dat.rds")) |> 
                          mutate(agree = "Disagree")) |> fix_healthcare()

fig_pid_agree = plot_conjoint(conjoint = fig_pid_dat |> 
                                filter(agree == "Agree"),
                              is_result = T,
                              lab = policies, 
                              weights = dta_grp$demog_weight[!is.na(dta_grp$dem_grp)],
                              use="for",
                              title=NULL,
                              grouped_data=T) +
  labs(subtitle = "Agree with Policy", x = NULL, y = NULL)

fig_pid_disagree = plot_conjoint(conjoint = fig_pid_dat |> 
                                   filter(agree == "Disagree"),
                                 is_result = T,
                                 lab = policies, 
                                 weights = dta_grp$demog_weight[!is.na(dta_grp$dem_grp)],
                                 use="against",
                                 title=NULL,
                                 grouped_data=T) +
  labs(subtitle = "Disagree with Policy", x = NULL, y = NULL)

fig_pid_pts = fig_pid_agree + fig_pid_disagree

print(fig_pid_pts)

ggsave(here("figures","appendix","figure_s6.png"), fig_pid_pts,
       dpi = 600, units = "in", width = 10, height = 9)

## Gender

# Agree/Disagree
fig_sex_dat = bind_rows(import(here("data","fig_sex_agree_dat.rds")) |> 
                       mutate(agree = "Agree"),
                     import(here("data","fig_sex_disagree_dat.rds")) |> 
                       mutate(agree = "Disagree")) |> fix_healthcare()

fig_sex_agree = plot_conjoint(conjoint = fig_sex_dat |> 
                                filter(agree == "Agree"),
                              is_result = T,
                              lab = policies, 
                              weights = dta_grp$demog_weight[!is.na(dta_grp$male_grp)],
                              use="for",
                              title=NULL,
                              grouped_data=T) +
  labs(subtitle = "Agree with Policy", x = NULL, y = NULL)

fig_sex_disagree = plot_conjoint(conjoint = fig_sex_dat |> 
                                   filter(agree == "Disagree"),
                                 is_result = T,
                                 lab = policies, 
                                 weights = dta_grp$demog_weight[!is.na(dta_grp$male_grp)],
                                 use="against",
                                 title=NULL,
                                 grouped_data=T) +
  labs(subtitle = "Disagree with Policy", x = NULL, y = NULL)

fig_sex_pts = fig_sex_agree + fig_sex_disagree

print(fig_sex_pts)

ggsave(here("figures","appendix","figure_s7.png"), fig_sex_pts,
       dpi = 600, units = "in", width = 10, height = 9)

## Race

# Agree/Disagree
fig_race_dat = bind_rows(import(here("data","fig_race_agree_dat.rds")) |> 
                          mutate(agree = "Agree"),
                        import(here("data","fig_race_disagree_dat.rds")) |> 
                          mutate(agree = "Disagree")) |> fix_healthcare()

fig_race_agree = plot_conjoint(conjoint = fig_race_dat |> 
                                filter(agree == "Agree"),
                              is_result = T,
                              lab = policies, 
                              weights = dta_grp$demog_weight[!is.na(dta_grp$white_grp)],
                              use="for",
                              title=NULL,
                              grouped_data=T) +
  labs(subtitle = "Agree with Policy", x = NULL, y = NULL)

fig_race_disagree = plot_conjoint(conjoint = fig_race_dat |> 
                                   filter(agree == "Disagree"),
                                 is_result = T,
                                 lab = policies, 
                                 weights = dta_grp$demog_weight[!is.na(dta_grp$white_grp)],
                                 use="against",
                                 title=NULL,
                                 grouped_data=T) +
  labs(subtitle = "Disagree with Policy", x = NULL, y = NULL)

fig_race_pts = fig_race_agree + fig_race_disagree

print(fig_race_pts)

ggsave(here("figures","appendix","figure_s8.png"), fig_race_pts,
       dpi = 600, units = "in", width = 10, height = 9)

ccat("See 'figure_s6.png' to 'figure_s8.png' for Figures S6-8 output")


